#include "garbage.h"
#include "types.h"

static garbage pile;

void * new_garbage(size_t nelem, size_t elsize) {
	garbage tail = pile;
	pile = (garbage) calloc(1, sizeof(struct garbage));
	pile->next = tail;
	pile->value = calloc(nelem, elsize);
	return pile->value;
}

void free_garbage(void) {
	while (pile) {
		garbage next = pile->next;
		/*
		fprintf(stderr, "freeing: garbage %p value %p\n", pile, pile->value);
		*/
		free(pile->value);
		free(pile);
		pile = next;
	}
}

void * garbage_pile(void) { return (void *) pile; }
